<template>
	<view class="address">
		<!-- 选择收货地址的按钮 -->
		<view v-if="JSON.stringify(address) === '{}'">
		<button type="primary" size="mini" class="btnAddress" @click="chooseAddress">请选择收货地址+</button>
		</view>
		<!-- 渲染收货地址的信息 -->
		<view class="address-info" v-else @click="chooseAddress">
			<view class="info-top">
				<view class="address-name">
					收货人:{{address.userName}}
				</view>
				<view class="address-phone">
					<text>电话:{{address.telNumber}}</text>
					<uni-icons type="forward" size="17"></uni-icons>
				</view>
			</view>
			<view class="info-bottom">
				收货地址：{{addressStr}}
			</view>
		</view>
	</view>
</template>

<script>
import {mapState,mapMutations,mapGetters} from 'vuex'
	export default {
		name:"my-address",
		computed:{
			...mapState('m_user',['address']),
			...mapGetters('m_user',['addressStr'])
		},
		data() {
			return {
			};
		},
		methods:{
			...mapMutations('m_user',['updateAddress']),
			async chooseAddress(){
			const [err,suc] = await	uni.chooseAddress().catch(err=>err)
			if(err === null && suc.errMsg === 'chooseAddress:ok'){
				// console.log(suc)
				this.updateAddress(suc);
				
			}
			},
			
		},
		
	}
</script>

<style lang="scss">
.address{
	width: 100%;
	height: 90px;
	border-bottom: 2px solid #c00000;
	display: flex;
	justify-content: center;
	align-items: center;
}
.address-info{
	padding: 10px 2px;
	width: 100%;
	display: flex;
	flex-direction: column;
	font-size: 12px;
	.info-top{
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 20px;
		.address-phone{
			display: flex;
		}
	}
}
</style>
